#ifndef __COMM_IPC_H__
#define __COMM_IPC_H__

#include <stdio.h>
#include <stdlib.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <sys/msg.h>

#define MSG_MAX_SIZE	4096

struct msgstruct {
	long int mtype; /* type of received/sent message */
	char mtext[1]; /* text of the message */
} _PACKET;

class CommMsgQueue {
private:
	key_t msgqKey;
	int msgqID;

public:
	CommMsgQueue();
	~CommMsgQueue();

	int Create(char *path, char proj);
	int Open(key_t keyval);
	int Close(void);
	int Delete(void);

	key_t GetKey(void) {
		return msgqKey;
	}
	int GetId(void) {
		return msgqID;
	}

	int Read(void *msgp, int size, long int mtype); //成功：字节数,失败<0
	int Write(void *msgp, int size, long int mtype); //成功0,失败<－1
	int Read(void *msgp, int size, long int mtype, int timeOut); //成功：字节数,失败<0,timeOut:ms
	int Write(void *msgp, int size, long int mtype, int timeOut); //成功0,失败<－1,timeOut:ms
};

#endif /* IPC_H_ */
